package com.linko.intelligent.common.handler;

import com.google.gson.Gson;
import com.linko.intelligent.base.CommonResponse;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class TokenAuthticationFailHandler {
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, Exception e) {
        CommonResponse res = CommonResponse.constructResponse(1018, e.getMessage());
        Gson gson = new Gson();
        try {
            response.getOutputStream().write(gson.toJson(res).getBytes(StandardCharsets.UTF_8));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    public void onNoAuthentication(HttpServletRequest request, HttpServletResponse response) {
        CommonResponse res = CommonResponse.constructResponse(1008, "无登陆信息");
        Gson gson = new Gson();
        try {
            response.getOutputStream().write(gson.toJson(res).getBytes(StandardCharsets.UTF_8));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
